package com.j3.db;

import java.util.Random;

public class Sequence {

	private final static Random RANDOM = new Random();
    private final static char[] digits = {
    	'0' , '1' , '2' , '3' , '4' , '5' ,
    	'6' , '7' , '8' , '9' , 'a' , 'b' ,
    	'c' , 'd' , 'e' , 'f' , 'g' , 'h' ,
    	'i' , 'j' , 'k' , 'l' , 'm' , 'n' ,
    	'o' , 'p' , 'q' , 'r' , 's' , 't' ,
    	'u' , 'v' , 'w' , 'x' , 'y' , 'z'
        };

	synchronized public static String next() {
		return getUniqueId();
	}

	public static String getUniqueId(final int len) {
		char[] buffer = new char[len];
		for (int i = 0; i < buffer.length; i++) {
			buffer[i] = digits[RANDOM.nextInt(36)];
		}
		return new String(buffer);
	}

	public static String getUniqueId() {
		return getUniqueId(8);
	}
}